package com.macro.mall.service.impl;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.common.exception.Asserts;
import com.macro.mall.mapper.MbrMemberCollectMapper;
import com.macro.mall.model.MbrMemberCollect;
import com.macro.mall.service.MbrMemberCollectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * MbrMemberCollect的服务接口的实现类
 * 
 * @author gaodx
 *
 */
@Slf4j
@Service
public class MbrMemberCollectServiceImpl implements MbrMemberCollectService {

    @Value("${log.isDebugEnabled:false}")
    private boolean isDebugEnabled;

	@Autowired
	private MbrMemberCollectMapper mbrMemberCollectMapper;

	@Override
	public List<MbrMemberCollect> find(MbrMemberCollect value) {
		//TODO这里可以做通过Assist做添加查询
		List<MbrMemberCollect> result = mbrMemberCollectMapper.selectMbrMemberCollect(null);
		if (isDebugEnabled) {
			log.debug("执行获取MbrMemberCollect数据集-->结果:", result);
		}
		return result;
	}
	@Override
	public MbrMemberCollect findOne(Long id) {
		if (id == null) {
			if (isDebugEnabled) {
				log.debug("执行通过MbrMemberCollect的id获得MbrMemberCollect对象-->失败:id不能为空");
			}
            Asserts.fail("执行通过MbrMemberCollect的id获得MbrMemberCollect对象-->失败:id不能为空");
		}
		MbrMemberCollect result = mbrMemberCollectMapper.selectMbrMemberCollectById(id);
		if (isDebugEnabled) {
			log.debug("执行通过MbrMemberCollect的id获得MbrMemberCollect对象-->结果:", result);
		}
		return result;
	}

	@Override
	public CommonResult saveNotNull(MbrMemberCollect value) {
		if (value == null) {
			if (isDebugEnabled) {
				log.debug("执行将MbrMemberCollect中属性值不为null的数据保存到数据库-->失败:对象不能为空");
			}
                Asserts.fail("失败:对象不能为空");
		}
		int result = mbrMemberCollectMapper.insertNotNullMbrMemberCollect(value);
		if (isDebugEnabled) {
			log.debug("执行将MbrMemberCollect中属性值不为null的数据保存到数据库-->结果:", result);
		}
            return CommonResult.success(null);
	}
	@Override
	public CommonResult updateNotNullById(MbrMemberCollect value) {
		if (value == null) {
			if (isDebugEnabled) {
				log.debug("执行通过MbrMemberCollect的id更新MbrMemberCollect中属性不为null的数据-->失败:对象为null");
			}
                Asserts.fail("执行通过MbrMemberCollect的id更新MbrMemberCollect中属性不为null的数据-->失败:对象为null");
		}
		int result = mbrMemberCollectMapper.updateNotNullMbrMemberCollectById(value);
		if (isDebugEnabled) {
			log.debug("执行通过MbrMemberCollect的id更新MbrMemberCollect中属性不为null的数据-->结果:", result);
		}
        return CommonResult.success(null);
	}

	@Override
	public CommonResult deleteById(Long id) {
		if (id == null) {
			if (isDebugEnabled) {
				log.debug("执行通过MbrMemberCollect的id删除MbrMemberCollect-->失败:id不能为空");
			}
                Asserts.fail("执行通过MbrMemberCollect的id删除MbrMemberCollect-->失败:id不能为空");
		}
		String[] ids= new String[1];
		ids[0]=id.toString();
		int result = mbrMemberCollectMapper.deleteMbrMemberCollectById(ids);
		if (isDebugEnabled) {
			log.debug("执行通过MbrMemberCollect的id删除MbrMemberCollect-->结果:", result);
		}
        return CommonResult.success(null);
	}


}